/* 通过promise封装wx原生api */
export default {
  /* 获取用户信息 */
  getSetting: function () {
    return new Promise((resolve, reject) => {
      wx.getSetting({
        withSubscriptions: true,
        success: (res) => {
          resolve(res)
        },
        fail: (err) => {
          reject(err)
        }
      })
    })
  },
  /* 打开用户授权界面 */
  openSetting: function () {
    return new Promise((resolve, reject) => {
      wx.openSetting({
        withSubscriptions: true,
        success: (result) => {
          resolve(result)
        },
        fail: (res) => {
          reject(res)
        }
      })
    })
  },
  //获取地址封装
  chooseAddress: function () {
    return new Promise((resolve, reject) => {
      wx.chooseAddress({
        success: (result) => {
          resolve(result)
        },
        fail: (res) => {
          reject(res)
        }
      })
    })
  },
  //提示框封装
  showToast: function (mag) {
    return new Promise((resolve, reject) => {
      wx.showToast({
        title: mag,
        icon: 'none',
        success: (res) => {
          resolve(res)
        },
        fail: (err) => {
          reject(err)
        }
      })
    })
  },
  //获取微信code
  login: function () {
    return new Promise((resolve, reject) => {
      //执行小程序登录
      wx.login({
        timeout: 1000,
        success(res) {
          resolve(res)
        },
        fail: (err) => {
          reject(err)
        }
      })
    })
  },
  //支付
  requestPayment: function (pay) {
    return new Promise((resolve, reject) => {
      //执行小程序登录
      wx.requestPayment({
        ...pay,
        success(res) {
          console.log("res", res)
          resolve(res)
        },
        fail: (err) => {
          console.log("err", err)
          reject(err)
        }
      })
    })
  }

}